package com.penghaisoft.microwms.base.web.auth.controller;

import com.penghaisoft.microwms.base.web.auth.service.IBaseUserDataauthTypeService;
import com.penghaisoft.microwms.common.base.model.BaseUserDataauthType;
import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/auth/data/type")
@Slf4j
public class BaseUserDataauthTypeController extends BaseController {

    @Autowired
    private IBaseUserDataauthTypeService baseUserDataauthTypeService;

    /**
    * 新增记录
    * @param baseUserDataauthType
    * @return
    */
    @PostMapping("c")
    public TransResult create(BaseUserDataauthType baseUserDataauthType) {
        baseUserDataauthType.preInsert();
        Resp resp =  baseUserDataauthTypeService.create(baseUserDataauthType);
        return fromResp(resp);
    }

    /**
    * 删除记录（逻辑删除active_flag=0)
    * @param baseUserDataauthType
    * @return
    */
    @PostMapping("d")
    public TransResult delete(BaseUserDataauthType baseUserDataauthType) {
        baseUserDataauthType.preUpdate();
        Resp resp =  baseUserDataauthTypeService.delete(baseUserDataauthType);
        return fromResp(resp);
    }

    /**
    * 查询列表
    * @param
    * @return
    */
    @PostMapping("list")
    public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "rows", defaultValue = "10") int rows, BaseUserDataauthType baseUserDataauthType) {
        Pager<BaseUserDataauthType> result = baseUserDataauthTypeService.findListByCondition(page,rows,baseUserDataauthType);
        return success(result);
    }

    /**
    * 查询单条
    * @param id
    * @return
    */
    @GetMapping("r/{id}")
    public TransResult queryById(@PathVariable String id) {
        BaseUserDataauthType baseUserDataauthType = baseUserDataauthTypeService.findById(id);
        return success(baseUserDataauthType);
    }

    /**
    * 修改记录
    * @param baseUserDataauthType
    * @return
    */
    @PostMapping("u")
    public TransResult update(BaseUserDataauthType baseUserDataauthType) {
        baseUserDataauthType.preUpdate();
        Resp resp =  baseUserDataauthTypeService.update(baseUserDataauthType);
        return fromResp(resp);
    }

}
